package com.karaku.karaku_collector;

import android.text.TextUtils;

import com.karaku.karaku_collector.collector.CollectorManager;
import com.karaku.karaku_collector.collector.CollectorStateManager;
import com.karaku.karaku_collector.util.LogUtil;
import com.umeng.analytics.MobclickAgent;

import java.util.HashMap;

/**
 * Created by guoping on 2017/10/31.
 */

public class UmengEventManager {

    public static void onCollectorErrorEvent(int collectorState, String desc) {
        String event = getEventKeyWithCollectorState(collectorState);
        if (event == null) {
            return;
        }
        HashMap<String, String> ps = new HashMap<>();
        String roomId = LocalSetting.getInstance().getRoomId();
        ps.put("roomId", roomId);
        if (!TextUtils.isEmpty(desc)) {
            ps.put("desc", desc);
        }
        LogUtil.d("EVENT", "event:" + event + " desc:" + desc);
        MobclickAgent.onEvent(App.getInstance(), event, ps);
    }

    private static String getEventKeyWithCollectorState(int collectorState) {
        switch (collectorState) {
            case CollectorStateManager.STATE_RETRY_CAMERA_ERROR:
                return "ERROR_CAMERA";
            case CollectorStateManager.STATE_RETRY_SDK_LAUNCH:
                return "ERROR_SDK_LAUNCH";
            case CollectorStateManager.STATE_RETRY_SDK_CONNECT:
                return "ERROR_SDK_CONNECT";
            case CollectorStateManager.STATE_RETRY_SDK_ERROR:
                return "ERROR_SDK_ERROR";
            case CollectorStateManager.STATE_RETRY_CHANNEL_KEY_EXPIRED:
                return "ERROR_CHANNEL_KEY_EXPIRED";
            case CollectorStateManager.STATE_RETRY_GET_CHANNEL_KEY:
                return "ERROR_GET_CHANNEL_KEY";
            case CollectorStateManager.STATE_RETRY_UPLOAD_ROOM_INFO:
                return "ERROR_UPLOAD_ROOM_INFO";
            case CollectorStateManager.STATE_RETRY_TIMEOUT:
                return "ERROR_TIMEOUT";
            default:
                return null;
        }
    }
}
